package cn.bon.emp.api.typeHandler;

import cn.bon.emp.api.enums.OrgLevel;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author Lc_cL
 * @Date 2023/12/25
 * @Description
 */

public class OrgLevelTypeHandler extends BaseTypeHandler<OrgLevel> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, OrgLevel orgLevel, JdbcType jdbcType) throws SQLException {
        ps.setString(i, orgLevel.getValue());
    }

    @Override
    public OrgLevel getNullableResult(ResultSet resultSet, String s) throws SQLException {

        return OrgLevel.fromValue(resultSet.getString(s));
    }

    @Override
    public OrgLevel getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return OrgLevel.fromValue(resultSet.getString(i));
    }

    @Override
    public OrgLevel getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return OrgLevel.fromValue(callableStatement.getString(i));
    }
}
